package cn.leaf.strategy;

import java.math.BigDecimal;

/**
 *
 * desc: 策略模式测试类
 *
 * Spring框架中的应用：
 * Spring MVC中 DispatcherServlet 初始化调用getDefaultStrategy(context, LocaleResolver.class)
 * SimpleInstantiationStrategy实例化对象
 * -----------------------------------
 * Jdk中的应用：
 * 集合的比较器Comparator、ThreadPoolExecutor的拒绝策略
 * -----------------------------------------------
 * @author twinkle-leaf
 * @version v1.0.0
 * slogan: There are no two identical leaves in the world.🍃
 *
 */
public class Test {
    public static void main(String[] args) {

        //1. vip顾客优惠策略
        DiscountStrategy vipCustomerStrategy = new VipCustomerStrategy();
        // 新顾客策略
        DiscountStrategy newCustomerStrategy = new NewCustomerStrategy();

        //2. 折扣上下文对象
        DiscountContext discountContext = new DiscountContext(vipCustomerStrategy);

        //3. 获取折扣价格
        BigDecimal price = discountContext.getPrice(new BigDecimal(100));
        System.out.println("最终价格：" + price);

        System.out.println("------------------------------");

        discountContext = new DiscountContext(newCustomerStrategy);
        price = discountContext.getPrice(new BigDecimal(100));
        System.out.println("最终价格：" + price);
    }
}
